<?php

/**
 * model_group
 */

class Model_group extends YOU {

	public function __construct()
	{
		parent::__construct();
	}


	/** 读取列表 **/
	public function getAll($field = "*")
	{
		$group_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_group` ");

		return $group_lists;
	}

	/** 读取信息 **/
	public function getInfo($group_id, $field = "*")
	{
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_group` WHERE group_id='{$group_id}' ");

		return $data;
	}

	/** 得到组权限 **/
	public function getPms( $group_ids = array() )
	{
		// 取得用户权限
		$user_pms = array();
		foreach ($group_ids as $group_id){
			$group_data = $this->getInfo($group_id);
			$group_pms  = unserialize($group_data['group_pms']);
			// 合并
			$user_pms = array_merge($user_pms, (array)$group_pms);

		}
		$user_pms = serialize($user_pms);

		return $user_pms;
	}

	/** 批量得到用户组名称 **/
	public function getNames($group_ids)
	{
		$group_name = array();
		$group_ids = unserialize($group_ids);

		if (!empty($group_ids)){
			foreach ($group_ids as $group_id){
				$group_data = $this->getInfo($group_id, "group_name");
				$group_name[] = $group_data['group_name'];
			}
		}
		return implode(",", $group_name);

	}

}



?>